<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是uboot移植的相关笔记。若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV05-01-uboot-07-uboot移植">
<meta property="og:url" content="https://sumumm.github.io/post/b353fdae.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是uboot移植的相关笔记。若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730160121375.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730160313896.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730160500995.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730160719820.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730160825353.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730161104638.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730161521072.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730170713377.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730202213328.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730220454609.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730220626808.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730224023173.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730224146997.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730224659211.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730230203861.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230731162034012.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230731162611666.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230731162842324.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230731163050919.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230731163602889.png">
<meta property="article:published_time" content="2023-09-08T11:23:03.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.041Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="(ALPHA)LV05-uboot与内核">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730160121375.png">


<link rel="canonical" href="https://sumumm.github.io/post/b353fdae.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/b353fdae.html","path":"post/b353fdae.html","title":"LV05-01-uboot-07-uboot移植"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV05-01-uboot-07-uboot移植 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81NXP%E5%8E%9F%E7%89%88u-boot%E7%BC%96%E8%AF%91%E6%B5%8B%E8%AF%95"><span class="nav-text">一、NXP原版u-boot编译测试</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E7%BC%96%E8%AF%91u-boot"><span class="nav-text">1. 编译u-boot</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%B8%8B%E8%BD%BD%E5%88%B0SD%E5%8D%A1"><span class="nav-text">2. 下载到SD卡</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%90%AF%E5%8A%A8ubuut%E5%B9%B6%E6%B5%8B%E8%AF%95"><span class="nav-text">3. 启动ubuut并测试</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E5%90%AF%E5%8A%A8uboot"><span class="nav-text">3.1 启动uboot</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-SD%E5%8D%A1%E5%92%8CeMMC%E6%B5%8B%E8%AF%95"><span class="nav-text">3.2 SD卡和eMMC测试</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-LCD%E9%A9%B1%E5%8A%A8"><span class="nav-text">3.3 LCD驱动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-4-%E7%BD%91%E7%BB%9C%E9%A9%B1%E5%8A%A8"><span class="nav-text">3.4 网络驱动</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E6%80%BB%E7%BB%93"><span class="nav-text">4. 总结</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81u-boot%E7%A7%BB%E6%A4%8D"><span class="nav-text">二、u-boot移植</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%B7%BB%E5%8A%A0%E8%87%AA%E5%B7%B1%E7%9A%84%E5%BC%80%E5%8F%91%E6%9D%BF"><span class="nav-text">1. 添加自己的开发板</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-%E6%B7%BB%E5%8A%A0%E5%BC%80%E5%8F%91%E6%9D%BF%E9%BB%98%E8%AE%A4%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="nav-text">1.1 添加开发板默认配置文件  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-%E6%B7%BB%E5%8A%A0%E5%BC%80%E5%8F%91%E6%9D%BF%E5%AF%B9%E5%BA%94%E7%9A%84%E5%A4%B4%E6%96%87%E4%BB%B6"><span class="nav-text">1.2 添加开发板对应的头文件  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-3-%E6%B7%BB%E5%8A%A0%E5%BC%80%E5%8F%91%E6%9D%BF%E5%AF%B9%E5%BA%94%E7%9A%84%E6%9D%BF%E7%BA%A7%E6%96%87%E4%BB%B6%E5%A4%B9"><span class="nav-text">1.3 添加开发板对应的板级文件夹  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-4-%E7%BC%96%E8%AF%91%E8%87%AA%E5%B7%B1%E6%B7%BB%E5%8A%A0%E7%9A%84%E5%BC%80%E5%8F%91%E6%9D%BF"><span class="nav-text">1.4 编译自己添加的开发板</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-LCD%E9%A9%B1%E5%8A%A8%E7%A7%BB%E6%A4%8D"><span class="nav-text">2. LCD驱动移植</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E4%BF%AE%E6%94%B9display%E6%95%B0%E7%BB%84"><span class="nav-text">2.1 修改display数组</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E4%BF%AE%E6%94%B9panel"><span class="nav-text">2.2 修改panel</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E6%9F%A5%E7%9C%8B%E6%95%88%E6%9E%9C"><span class="nav-text">2.3 查看效果</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E7%BD%91%E7%BB%9C%E9%A9%B1%E5%8A%A8%E7%A7%BB%E6%A4%8D"><span class="nav-text">3. 网络驱动移植</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-ALPHA%E5%BC%80%E5%8F%91%E6%9D%BF%E7%BD%91%E7%BB%9C%E7%AE%80%E4%BB%8B"><span class="nav-text">3.1 ALPHA开发板网络简介</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-1-%E6%A6%82%E8%BF%B0"><span class="nav-text">3.1.1 概述</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-2-%E7%A1%AC%E4%BB%B6%E8%BF%9E%E6%8E%A5"><span class="nav-text">3.1.2 硬件连接</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E7%BD%91%E7%BB%9C%E9%A9%B1%E5%8A%A8%E7%A7%BB%E6%A4%8D"><span class="nav-text">3.2 网络驱动移植</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-2-1-%E7%BD%91%E7%BB%9C-PHY-%E5%9C%B0%E5%9D%80%E4%BF%AE%E6%94%B9"><span class="nav-text">3.2.1 网络 PHY 地址修改  </span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-2-2-%E5%88%A0%E9%99%A4-uboot-%E4%B8%AD-74LV595-%E7%9A%84%E9%A9%B1%E5%8A%A8%E4%BB%A3%E7%A0%81"><span class="nav-text">3.2.2 删除 uboot 中 74LV595 的驱动代码  </span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-2-3-%E6%B7%BB%E5%8A%A0-I-MX6U-ALPHA-%E5%BC%80%E5%8F%91%E6%9D%BF%E7%BD%91%E7%BB%9C%E5%A4%8D%E4%BD%8D%E5%BC%95%E8%84%9A%E9%A9%B1%E5%8A%A8"><span class="nav-text">3.2.3 添加 I.MX6U-ALPHA 开发板网络复位引脚驱动  </span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-2-4-%E4%BF%AE%E6%94%B9%E5%87%BD%E6%95%B0-genphy-update-link"><span class="nav-text">3.2.4 修改函数 genphy_update_link  </span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E7%BC%96%E8%AF%91%E4%B8%8B%E8%BD%BD%E6%B5%8B%E8%AF%95"><span class="nav-text">3.3 编译下载测试</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%85%B6%E4%BB%96%E4%BF%AE%E6%94%B9"><span class="nav-text">4. 其他修改</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81bootcmd%E4%B8%8Ebootargs"><span class="nav-text">三、bootcmd与bootargs</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%A6%82%E8%BF%B0"><span class="nav-text">1. 概述</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-bootcmd"><span class="nav-text">2. bootcmd</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-bootargs"><span class="nav-text">3. bootargs</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/b353fdae.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV05-01-uboot-07-uboot移植 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV05-01-uboot-07-uboot移植
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-08 19:23:03" itemprop="dateCreated datePublished" datetime="2023-09-08T19:23:03+08:00">2023-09-08</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/" itemprop="url" rel="index"><span itemprop="name">02IMX6ULL平台</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/" itemprop="url" rel="index"><span itemprop="name">LV05-uboot与内核</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>10k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>38 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是uboot移植的相关笔记。若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows版本</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu版本</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">终端软件</td>        <td align="left">MobaXterm(Professional Edition v23.0 Build 5042 (license))</td>      </tr>    <tr>        <td align="center">Linux开发板</td>        <td align="left">正点原子 i.MX6ULL Linux 阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr>    <tr>        <td align="center">Win32DiskImager</td>        <td align="left">Win32DiskImager v1.0</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="5">官方网站</td>        <td align="left"><a href="https://www.arm.com/" target="_blank">https://www.arm.com/</a></td>        <td align="left">ARM官方网站，在这里我们可以找到Cotex-Mx以及ARMVx的一些文档</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxp.com.cn/" target="_blank">https://www.nxp.com.cn/ </a></td>        <td align="left">NXP官方网站</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxpic.org.cn/" target="_blank">https://www.nxpic.org.cn/</a></td><td align="left">NXP 官方社区</td>    </tr>    <tr>        <td align="left"><a href="https://u-boot.readthedocs.io/en/latest/" target="_blank">https://u-boot.readthedocs.io/en/latest/</a></td><td align="left">u-boot官网</td>    </tr>    <tr>        <td align="left"><a href="https://www.kernel.org/" target="_blank">https://www.kernel.org/</a></td><td align="left">linux内核官网</td>    </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="4">NXP</td>        <td align="left"><a href="https://github.com/nxp-imx" target="_blank">https://github.com/nxp-imx</a></td>        <td align="left">NXP imx开发资源GitHub组织，里边会有u-boot和linux内核的仓库</td>    </tr>    <tr>        <td align="left"><a href="https://elixir.bootlin.com/linux/latest/source" target="_blank">https://elixir.bootlin.com/linux/latest/source</a></td>        <td align="left">在线阅读linux kernel源码</td>    </tr>    <tr>        <td align="left"><a href="https://github.com/nxp-imx/linux-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga" target="_blank">nxp-imx/linux-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga</a></td>        <td align="left">NXP linux内核仓库tags中的rel_imx_4.1.15_2.1.0_ga</td>    </tr>    <tr>        <td align="left"><a href="https://github.com/nxp-imx/uboot-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga" target="_blank">nxp-imx/uboot-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga</a></td>        <td align="left">NXP u-boot仓库tags中的rel_imx_4.1.15_2.1.0_ga</td>    </tr>    <tr>        <td align="center" rowspan="2">I.MX6ULL</td>        <td align="left"><a href="https://www.nxp.com.cn/docs/en/data-sheet/IMX6ULLIEC.pdf" target="_blank">i.MX 6ULL Applications Processors for Industrial Products</a></td>        <td align="left">I.MX6ULL 芯片手册（datasheet，可以在线查看）</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxp.com.cn/webapp/Download?colCode=IMX6ULLRM&lang_cd=zh" target="_blank">i.MX 6ULL Applications ProcessorReference Manual</a></td>        <td align="left">I.MX6ULL 参考手册（下载后才能查看，需要登录NXP官网）</td>    </tr></table>
              </div>
            </details>

<p>这一节我们就来看一下，如何移植NXP官方提供的uboot，以便于适配我们的开发板。</p>
<h1 id="一、NXP原版u-boot编译测试"><a href="#一、NXP原版u-boot编译测试" class="headerlink" title="一、NXP原版u-boot编译测试"></a><font size=3>一、NXP原版u-boot编译测试</font></h1><h2 id="1-编译u-boot"><a href="#1-编译u-boot" class="headerlink" title="1. 编译u-boot"></a><font size=3>1. 编译u-boot</font></h2><p>我们先来编译和下载NXP原版的u-boot：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean</span><br><span class="line">make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- mx6ull_14x14_evk_emmc_defconfig </span><br><span class="line">make V=0 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16</span><br></pre></td></tr></table></figure>

<p>编译完成后会生成的文件是直接有u-boot.imx文件的，所以我们在ubuntu下可以直接下载这个文件到SD卡。</p>
<h2 id="2-下载到SD卡"><a href="#2-下载到SD卡" class="headerlink" title="2. 下载到SD卡"></a><font size=3>2. 下载到SD卡</font></h2><p>我们可以使用以下命令下载：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo dd if=u-boot.imx of=/dev/sdc bs=1k seek=1 conv=fsync</span><br></pre></td></tr></table></figure>

<p>注意，我们要提前确认好sd卡在ubuntu中的节点，卸载完成会有以下提示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730160121375.png" alt="image-20230730160121375" style="zoom:50%;" />

<h2 id="3-启动ubuut并测试"><a href="#3-启动ubuut并测试" class="headerlink" title="3. 启动ubuut并测试"></a><font size=3>3. 启动ubuut并测试</font></h2><h3 id="3-1-启动uboot"><a href="#3-1-启动uboot" class="headerlink" title="3.1 启动uboot"></a><font size=3>3.1 启动uboot</font></h3><p>我们将拨码开关拨到SD卡启动，然后连接好串口，就会看到如下打印信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730160313896.png" alt="image-20230730160313896" style="zoom:50%;" />

<p>这里就会显示出当前uboot的编译时间还有uboot的版本，这里显示的时间就是我刚刚编译的。</p>
<h3 id="3-2-SD卡和eMMC测试"><a href="#3-2-SD卡和eMMC测试" class="headerlink" title="3.2 SD卡和eMMC测试"></a><font size=3>3.2 SD卡和eMMC测试</font></h3><p>由于正点原子的开发板是参考NXP的imx6ull evk评估板进行设计的，所以SD卡和eMMC的驱动是直接可以用的，不需要进行移植。我们在串口终端输入以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">=&gt; mmc list</span><br></pre></td></tr></table></figure>

<p>然后就会看到有以下信息显示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730160500995.png" alt="image-20230730160500995" style="zoom:50%;" />

<p>可以看出当前有两个 MMC 设备，检查每个 MMC 设备信息，先检查 MMC 设备 0，输入如下命令：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">=&gt; mmc dev 0</span><br><span class="line">=&gt; mmc info</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730160719820.png" alt="image-20230730160719820" style="zoom:50%;" />

<p>可以看出， mmc 设备 0 是 SD 卡， SD 卡容量为 3.7GB，这个和我所使用的SD 卡信息相符，说明 SD 卡驱动正常。再来检查 MMC 设备 1，输入如下命令：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">=&gt; mmc dev 1</span><br><span class="line">=&gt; mmc info</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730160825353.png" alt="image-20230730160825353" style="zoom:50%;" />

<p>可以看出， mmc 设备 1 为 EMMC，容量为 7.3GB，说明 EMMC 驱动也成功，SD 卡和 EMMC 的驱动都没问题。  </p>
<h3 id="3-3-LCD驱动"><a href="#3-3-LCD驱动" class="headerlink" title="3.3 LCD驱动"></a><font size=3>3.3 LCD驱动</font></h3><p>如果 uboot 中的 LCD 驱动正确的话，启动 uboot 以后 LCD 上应该会显示出 NXP 的 logo，如下图  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730161104638.png" alt="image-20230730161104638" style="zoom:50%;" />

<p>我用的是在正点原子的 4.3 寸 800x480 分辨率的屏幕。因为 NXP 官方 I.MX6ULL 开发板的屏幕就是 4.3 寸 480x272 分辨率的，所以 uboot 默认 LCD 驱动是 4.3 寸 480x272 分辨率的。所以这里，驱动虽然没问题，但是吧这个显示是多少有点问题的。后边再说怎么移植。</p>
<h3 id="3-4-网络驱动"><a href="#3-4-网络驱动" class="headerlink" title="3.4 网络驱动"></a><font size=3>3.4 网络驱动</font></h3><p>uboot 启动的时候提示“Board Net Initialization Failed”和“No ethernet found.”这两行，说明网络驱动也有问题  ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730161521072.png" alt="image-20230730161521072" style="zoom:50%;" />

<h2 id="4-总结"><a href="#4-总结" class="headerlink" title="4. 总结"></a><font size=3>4. 总结</font></h2><p>总结一下 NXP 官方 I.MX6ULL EVK 开发板的 uboot 在正点原子 EMMC 版本 I.MX6ULL开发板上的运行情况：</p>
<p>（1）uboot 启动正常， DRAM 识别正确， SD 卡和 EMMC 驱动正常。</p>
<p>（2）uboot 里面的 LCD 驱动默认是给 4.3 寸 480x272 分辨率的，如果使用的其他分辨率的屏幕需要修改驱动。</p>
<p>（3）网络不能工作，识别不出来网络信息，需要修改驱动。</p>
<p>接下来我们要做的工作如下：</p>
<p>（1）前面我们一直使用着 NXP 官方开发板的 uboot 配置，接下来需要在 uboot 中添加我们自己的开发板，也就是正点原子的 I.MX6ULL 开发板。</p>
<p>（2）解决 LCD 驱动和网络驱动的问题。  </p>
<h1 id="二、u-boot移植"><a href="#二、u-boot移植" class="headerlink" title="二、u-boot移植"></a><font size=3>二、u-boot移植</font></h1><h2 id="1-添加自己的开发板"><a href="#1-添加自己的开发板" class="headerlink" title="1. 添加自己的开发板"></a><font size=3>1. 添加自己的开发板</font></h2><p>NXP 官方 uboot 中默认都是 NXP 自己的开发板，虽说我们可以直接在官方的开发板上直接修改，使 uboot 可以完整的运行在我们的板子上。但是为了学习，我们还是要自己添加一个开发板。接下来我们就参考 NXP 官方的 I.MX6ULL EVK 开发板，学习如何在 uboot 中添加我们的开发板或者开发平台。    </p>
<h3 id="1-1-添加开发板默认配置文件"><a href="#1-1-添加开发板默认配置文件" class="headerlink" title="1.1 添加开发板默认配置文件  "></a><font size=3>1.1 添加开发板默认配置文件  </font></h3><p>先在 configs 目录下创建默认配置文件，复制 mx6ull_14x14_evk_emmc_defconfig，然后重命名为 mx6ull_alpha_emmc_defconfig，命令如下：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd configs</span><br><span class="line">cp mx6ull_14x14_evk_emmc_defconfig mx6ull_alpha_emmc_defconfig</span><br></pre></td></tr></table></figure>

<p>然后就是修改这个文件，可以看这里：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/linux-uboot/commit/6c59eb4b5f3dffff441ebb72f41461f164934df0">feat:修改开发板默认配置文件 · 6c59eb4 · sumumm&#x2F;u-boot - Gitee.com</a></p>
<h3 id="1-2-添加开发板对应的头文件"><a href="#1-2-添加开发板对应的头文件" class="headerlink" title="1.2 添加开发板对应的头文件  "></a><font size=3>1.2 添加开发板对应的头文件  </font></h3><p>在目录 include&#x2F;configs 下 添 加 I.MX6ULL-ALPHA 开发板对应的头文件 ， 复 制 include&#x2F;configs&#x2F;mx6ullevk.h，并重命名为mx6ull_alpha_emmc.h，命令如下：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp include/configs/mx6ullevk.h include/configs/mx6ull_alpha_emmc.h</span><br></pre></td></tr></table></figure>

<p>mx6ull_alientek_emmc.h 里面有很多宏定义，这些宏定义基本用于配置 uboot，也有一些I.MX6ULL 的配置项目。如果我们自己要想使能或者禁止 uboot 的某些功能，那就在mx6ull_alpha_emmc.h 里面做修改即可。 mx6ull_alpha_emmc.h 里面的内容比较多，可以去掉一些用不到的配置。可以查看这里：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/linux-uboot/commit/edff99872c05338674abcfe1fe2923b586277f19">feat:修改开发板对应的头文件 · edff998 · sumumm&#x2F;u-boot - Gitee.com</a></p>
<h3 id="1-3-添加开发板对应的板级文件夹"><a href="#1-3-添加开发板对应的板级文件夹" class="headerlink" title="1.3 添加开发板对应的板级文件夹  "></a><font size=3>1.3 添加开发板对应的板级文件夹  </font></h3><p>uboot 中每个板子都有一个对应的文件夹来存放板级文件，比如开发板上外设驱动文件等等。 NXP 的 I.MX 系列芯片的所有板级文件夹都存放在board&#x2F;freescale 目录下，在这个目录下有个名为 mx6ullevk 的文件夹，这个文件夹就是 NXP 官方 I.MX6ULL EVK 开发板的板级文件夹。复制 mx6ullevk，将其重命名为 mx6ull_alpha_emmc，命令如下：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd board/freescale/</span><br><span class="line">cp mx6ullevk/ -r mx6ull_alpha_emmc</span><br></pre></td></tr></table></figure>

<p>然后就是对相关文件的修改了，可以看这里：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/linux-uboot/commit/1df79f66ec537b6d87f7e32a8f645d13123eb0d5">feat:修改开发板对应的板级文件夹相关文件 · 1df79f6 · sumumm&#x2F;u-boot - Gitee.com</a></p>
<h3 id="1-4-编译自己添加的开发板"><a href="#1-4-编译自己添加的开发板" class="headerlink" title="1.4 编译自己添加的开发板"></a><font size=3>1.4 编译自己添加的开发板</font></h3><p>这里直接修改之前的脚本就可以了，可以看这里：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/linux-uboot/commit/c3422f76fd853ceafe7be8b17d303676322bfa27">feat:修改编译脚本，编译添加的板子 · c3422f7 · sumumm&#x2F;u-boot - Gitee.com</a>。理说按上边的步骤是不会有报错的，当编译完成后，可以搜索一下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grep -nR &quot;mx6ull_alpha_emmc.h&quot;</span><br></pre></td></tr></table></figure>

<p>如果有很多文件都引用了mx6ull_alpha_emmc.h这个头文件，那就说明新板子添加成功 。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730170713377.png" alt="image-20230730170713377" style="zoom:50%;" />

<h2 id="2-LCD驱动移植"><a href="#2-LCD驱动移植" class="headerlink" title="2. LCD驱动移植"></a><font size=3>2. LCD驱动移植</font></h2><p>一般 uboot 中修改驱动基本都是在 xxx.h 和 xxx.c 这两个文件中进行的， xxx 为板子名称，比如 mx6ull_alpha_emmc.h 和 mx6ull_alpha_emmc.c 这两个文件。一般修改 LCD 驱动重点注意以下几点：</p>
<p>（1）LCD 所使用的 GPIO，查看 uboot 中 LCD 的 IO 配置是否正确。</p>
<p>（2）LCD 背光引脚 GPIO 的配置。</p>
<p>（3）LCD 配置参数是否正确。  </p>
<h3 id="2-1-修改display数组"><a href="#2-1-修改display数组" class="headerlink" title="2.1 修改display数组"></a><font size=3>2.1 修改display数组</font></h3><p>正点原子的 I.MX6U-ALPHA 开发板 LCD 原理图和 NXP 官方 I.MX6ULL 开发板一致，也就是 LCD 的 IO 和背光 IO 都一样的，所以 IO 部分就不用修改了。需要修改的之后 LCD 参数，  打开文件 mx6ull_alpha_emmc.c，找到如下所示内容：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">display_info_t</span> <span class="title">const</span> <span class="title">displays</span>[] =</span> &#123;&#123;</span><br><span class="line">	.bus = MX6UL_LCDIF1_BASE_ADDR,</span><br><span class="line">	.addr = <span class="number">0</span>,</span><br><span class="line">	.pixfmt = <span class="number">24</span>,</span><br><span class="line">	.detect = <span class="literal">NULL</span>,</span><br><span class="line">	.enable	= do_enable_parallel_lcd,</span><br><span class="line">	.mode	= &#123;</span><br><span class="line">		.name			= <span class="string">&quot;TFT43AB&quot;</span>,</span><br><span class="line">		.xres           = <span class="number">480</span>,</span><br><span class="line">		.yres           = <span class="number">272</span>,</span><br><span class="line">		.pixclock       = <span class="number">108695</span>,</span><br><span class="line">		.left_margin    = <span class="number">8</span>,</span><br><span class="line">		.right_margin   = <span class="number">4</span>,</span><br><span class="line">		.upper_margin   = <span class="number">2</span>,</span><br><span class="line">		.lower_margin   = <span class="number">4</span>,</span><br><span class="line">		.hsync_len      = <span class="number">41</span>,</span><br><span class="line">		.vsync_len      = <span class="number">10</span>,</span><br><span class="line">		.sync           = <span class="number">0</span>,</span><br><span class="line">		.vmode          = FB_VMODE_NONINTERLACED</span><br><span class="line">&#125; &#125; &#125;;</span><br></pre></td></tr></table></figure>

<p>上边的代码中定义了一个变量 displays，类型为 display_info_t，这个结构体是 LCD信息结构体，其中包括了 LCD 的分辨率，像素格式， LCD 的各个参数等。 display_info_t 定义在文件 arch&#x2F;arm&#x2F;include&#x2F;asm&#x2F;imx-common&#x2F;video.h 中  ：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">display_info_t</span> &#123;</span></span><br><span class="line">	<span class="type">int</span>	bus;</span><br><span class="line">	<span class="type">int</span>	addr;</span><br><span class="line">	<span class="type">int</span>	pixfmt;</span><br><span class="line">	<span class="type">int</span>	(*detect)(<span class="keyword">struct</span> <span class="type">display_info_t</span> <span class="type">const</span> *dev);</span><br><span class="line">	<span class="type">void</span>	(*enable)(<span class="keyword">struct</span> <span class="type">display_info_t</span> <span class="type">const</span> *dev);</span><br><span class="line">	<span class="class"><span class="keyword">struct</span>	<span class="title">fb_videomode</span> <span class="title">mode</span>;</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>pixfmt 是像素格式，也就是一个像素点是多少位，如果是 RGB565 的话就是 16 位，如果是 888 的话就是 24 位，一般使用 RGB888。结构体 display_info_t 还有个 mode 成员变量，此成员变量也是个结构体，为 fb_videomode，定义在文件 include&#x2F;linux&#x2F;fb.h 中，定义如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">fb_videomode</span> &#123;</span></span><br><span class="line">	<span class="type">const</span> <span class="type">char</span> *name;	<span class="comment">/* optional */</span></span><br><span class="line">	u32 refresh;		<span class="comment">/* optional */</span></span><br><span class="line">	u32 xres;</span><br><span class="line">	u32 yres;</span><br><span class="line">	u32 pixclock;</span><br><span class="line">	u32 left_margin;</span><br><span class="line">	u32 right_margin;</span><br><span class="line">	u32 upper_margin;</span><br><span class="line">	u32 lower_margin;</span><br><span class="line">	u32 hsync_len;</span><br><span class="line">	u32 vsync_len;</span><br><span class="line">	u32 sync;</span><br><span class="line">	u32 vmode;</span><br><span class="line">	u32 flag;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>结构体 fb_videomode 里面的成员变量为 LCD 的参数，这些成员变量函数如下：</p>
<blockquote>
<p><strong>name</strong>： LCD 名字，要和环境变量中的 panel 相等。</p>
<p><strong>xres、 yres</strong>： LCD X 轴和 Y 轴像素数量。</p>
<p><strong>pixclock</strong>：像素时钟，每个像素时钟周期的长度，单位为皮秒。</p>
<p><strong>left_margin</strong>： HBP，水平同步后肩。</p>
<p><strong>right_margin</strong>： HFP，水平同步前肩。</p>
<p><strong>upper_margin</strong>： VBP，垂直同步后肩。</p>
<p><strong>lower_margin</strong>： VFP，垂直同步前肩。</p>
<p><strong>hsync_len</strong>： HSPW，行同步脉宽。</p>
<p><strong>vsync_len</strong>： VSPW，垂直同步脉宽。  </p>
<p><strong>vmode</strong>： 大多数使用 FB_VMODE_NONINTERLACED，也就是不使用隔行扫描。  </p>
</blockquote>
<p>关于像素时钟如何计算，后边学习LCD再说，这里直接参考正点原子出厂uboot进行配置即可（但是似乎有问题，我后来又改了）：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">display_info_t</span> <span class="title">const</span> <span class="title">displays</span>[] =</span> &#123;</span><br><span class="line">	&#123;</span><br><span class="line">		.bus = MX6UL_LCDIF1_BASE_ADDR,</span><br><span class="line">		.addr = <span class="number">0</span>,</span><br><span class="line">		.pixfmt = <span class="number">24</span>,</span><br><span class="line">		.detect = <span class="literal">NULL</span>,</span><br><span class="line">		.enable = do_enable_parallel_lcd,</span><br><span class="line">		.mode   = &#123;</span><br><span class="line">			.name           = <span class="string">&quot;ATK-LCD-4.3-800x480&quot;</span>,</span><br><span class="line">			.xres           = <span class="number">800</span>,</span><br><span class="line">			.yres           = <span class="number">480</span>,</span><br><span class="line">			.pixclock       = <span class="number">32258</span>, <span class="comment">/* 像素时钟，每个像素时钟周期的长度，单位为皮秒。 */</span></span><br><span class="line">			.left_margin    = <span class="number">88</span>,    <span class="comment">/* HBPD */</span></span><br><span class="line">			.right_margin   = <span class="number">40</span>,    <span class="comment">/* HFPD */</span></span><br><span class="line">			.upper_margin   = <span class="number">32</span>,    <span class="comment">/* VBPD */</span></span><br><span class="line">			.lower_margin   = <span class="number">13</span>,    <span class="comment">/* VFPD */</span></span><br><span class="line">			.hsync_len      = <span class="number">48</span>,    <span class="comment">/* HSPW */</span></span><br><span class="line">			.vsync_len      = <span class="number">3</span>,     <span class="comment">/* VSPW */</span></span><br><span class="line">			.sync           = <span class="number">0</span>,</span><br><span class="line">			.vmode          = FB_VMODE_NONINTERLACED</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;,</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>查阅资料会得到使用的这款4.3寸LCD屏幕的参数如下：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>参考值</th>
<th>单位</th>
</tr>
</thead>
<tbody><tr>
<td>水平显示区域</td>
<td>800</td>
<td>tCLK</td>
</tr>
<tr>
<td>HSPW(thp)</td>
<td>48</td>
<td>tCLK</td>
</tr>
<tr>
<td>HBP(thb)</td>
<td>88</td>
<td>tCLK</td>
</tr>
<tr>
<td>HFP(thf)</td>
<td>40</td>
<td>tCLK</td>
</tr>
<tr>
<td>垂直显示区域</td>
<td>480</td>
<td>th</td>
</tr>
<tr>
<td>VSPW(tvp)</td>
<td>3</td>
<td>th</td>
</tr>
<tr>
<td>VBP(tvb)</td>
<td>32</td>
<td>th</td>
</tr>
<tr>
<td>VFP(tvf)</td>
<td>13</td>
<td>th</td>
</tr>
<tr>
<td>像素时钟</td>
<td>31</td>
<td>MHz</td>
</tr>
</tbody></table>
<p>其中，pixclock的计算方式如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pixclock = 1/像素时钟 * 10^12</span><br></pre></td></tr></table></figure>

<h3 id="2-2-修改panel"><a href="#2-2-修改panel" class="headerlink" title="2.2 修改panel"></a><font size=3>2.2 修改panel</font></h3><p>打开 mx6ull_alpha_emmc.h，找到所有如下语句：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">panel=TFT43AB</span><br></pre></td></tr></table></figure>

<p>将其修改为上边的displays数组中.name成员的值：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">panel=ATK-LCD<span class="number">-4.3</span><span class="number">-800</span>x480</span><br></pre></td></tr></table></figure>

<h3 id="2-3-查看效果"><a href="#2-3-查看效果" class="headerlink" title="2.3 查看效果"></a><font size=3>2.3 查看效果</font></h3><p>将编译的uboot烧写到SD卡中，我们从SD卡启动：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730202213328.png" alt="image-20230730202213328" style="zoom:50%;" />

<p>会看到这里已经修改了，但是最后效果似乎不是很好，还不清楚是哪里的问题，等后边学习了LCD驱动后再查吧。</p>
<h2 id="3-网络驱动移植"><a href="#3-网络驱动移植" class="headerlink" title="3. 网络驱动移植"></a><font size=3>3. 网络驱动移植</font></h2><h3 id="3-1-ALPHA开发板网络简介"><a href="#3-1-ALPHA开发板网络简介" class="headerlink" title="3.1 ALPHA开发板网络简介"></a><font size=3>3.1 ALPHA开发板网络简介</font></h3><h4 id="3-1-1-概述"><a href="#3-1-1-概述" class="headerlink" title="3.1.1 概述"></a><font size=3>3.1.1 概述</font></h4><p>I.MX6UL&#x2F;ULL 内部有个以太网 MAC 外设，也就是 ENET，需要外接一个 PHY 芯片来实现网络通信功能，也就是内部 MAC+外部 PHY 芯片的方案。在一些没有内部 MAC 的 CPU 中，比如三星的 2440， 4412 等，就会采用 DM9000 来实现联网功能。 DM9000 提供了一个类似 SRAM 的访问接口，主控 CPU 通过这个接口即可与DM9000 进行通信， DM9000 就是一个 MAC+PHY 芯片。这个方案就相当于外部 MAC+外部PHY，那么 I.MX6U 这样的内部 MAC+PHY 芯片与 DM9000 方案比有什么优势吗？首先就是通信效率和速度，一般 SOC 内部的 MAC 是带有一个专用 DMA 的，专门用于处理网络数据包，采用 SRAM 来读写 DM9000 的速度是压根就没法和内部 MAC+外部 PHY 芯片的速度比。采用外部 DM9000 完全是无奈之举，谁让2440， 4412 这些芯片内部没有以太网外设呢，现在又想用有线网络，没有办法只能找个 DM9000 的方案。从这里也可以看出，三星的 2440、 4412 这些芯片设计之初就不是给工业产品用的，他们是给消费类电子使用的，比如手机、平板等，手机或平板要上网，可以通过 WIFI 或者 4G，我是没有见过哪个手机或者平板上网是要接根网线的。正点原子的 I.MX6U-ALPHA 开发板也可以通过 WIFI 或者 4G 上网，这个后边就会了解到。</p>
<p>I.MX6UL&#x2F;ULL 有两个网络接口 ENET1 和 ENET2，正点原子的 I.MX6U-ALPHA 开发板提供了这两个网络接口，其中 ENET1 和 ENET2 都使用 LAN8720A 作为 PHY 芯片。 NXP 官方的I.MX6ULL EVK 开发板使用 KSZ8081 这颗 PHY 芯片， LAN8720A 相比 KSZ8081 具有体积小、外围器件少、价格便宜等优点。直接使用 KSZ8081 固然可以，但是我们在实际的产品中不一定会使用 KSZ8081，有时候为了降低成本会选择其他的 PHY 芯片，这个时候就有个问题：换了PHY 芯片以后网络驱动怎么办？为此，正点原子的 I.MX6U-ALPHA 开发板将 ENET1 和 ENET2的 PHY 换成了 LAN8720A，所以NXP原厂的uboot中的网络驱动就无法使用了，我们就需要进行移植了。  </p>
<h4 id="3-1-2-硬件连接"><a href="#3-1-2-硬件连接" class="headerlink" title="3.1.2 硬件连接"></a><font size=3>3.1.2 硬件连接</font></h4><p>I.MX6U-ALPHA 开发板 ENET1 的网络原理图如图所示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730220454609.png" alt="image-20230730220454609" style="zoom:50%;" />

<p>ENET1 的网络 PHY 芯片为 LAN8720A，通过 RMII 接口与 I.MX6ULL 相连，正点原子I.MX6U-ALPHA 开发板的 ENET1 引脚与 NXP 官方的 I.MX6ULL EVK 开发板基本一样，唯独复位引脚不同。从图总可以看出，正点原子 I.MX6U-ALPHA 开发板的 ENET1 复位引脚ENET1_RST 接到了 I.M6ULL 的 SNVS_TAMPER7 这个引脚上。</p>
<p>LAN8720A 内部是有寄存器的， I.MX6ULL 会读取 LAN8720 内部寄存器来判断当前的物理链接状态、连接速度(10M 还是 100M)和双工状态(半双工还是全双工)。 I.MX6ULL 通过 MDIO接口来读取 PHY 芯片的内部寄存器， MDIO 接口有两个引脚， ENET_MDC 和 ENET_MDIO，ENET_MDC 提供时钟， ENET_MDIO 进行数据传输。一个 MDIO 接口可以管理 32 个 PHY 芯片，同一个 MDIO 接口下的这些 PHY 使用不同的器件地址来做区分， MIDO 接口通过不同的器件地址即可访问到相应的 PHY 芯片。 I.MX6U-ALPHA 开发板 ENET1 上连接的 LAN8720A器件地址为 0X0，所示我们要修改 ENET1 网络驱动的话重点就三点 ：</p>
<p>（1） ENET1 复位引脚初始化。</p>
<p>（2）LAN8720A 的器件 ID。</p>
<p>（3） LAN8720 驱动  </p>
<p>再来看一下 ENET2 的原理图，如图  ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730220626808.png" alt="image-20230730220626808" style="zoom:50%;" />

<p>关于 ENET2 网络驱动的修改也注意一下三点：</p>
<p>（1）ENET2 的复位引脚，从图 33.2.7.2 可以看出， ENET2 的复位引脚 ENET2_RST 接到了 I.MX6ULL 的 SNVS_TAMPER8 上。</p>
<p>（2）ENET2 所使用的 PHY 芯片器件地址，从图 33.2.7.2 可以看出， PHY 器件地址为 0X1。</p>
<p>（3） LAN8720 驱动， ENET1 和 ENET2 都使用的 LAN8720，所以驱动肯定是一样的。  </p>
<h3 id="3-2-网络驱动移植"><a href="#3-2-网络驱动移植" class="headerlink" title="3.2 网络驱动移植"></a><font size=3>3.2 网络驱动移植</font></h3><h4 id="3-2-1-网络-PHY-地址修改"><a href="#3-2-1-网络-PHY-地址修改" class="headerlink" title="3.2.1 网络 PHY 地址修改  "></a><font size=3>3.2.1 网络 PHY 地址修改  </font></h4><p>首先修改 uboot 中的 ENET1 和 ENET2 的 PHY 地址和驱动，打开 mx6ull_alpha_emmc.h这个文件，找到如下代码  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">ifdef</span> CONFIG_CMD_NET</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_CMD_PING</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_CMD_DHCP</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_CMD_MII</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_FEC_MXC</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_MII</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_FEC_ENET_DEV		1</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">if</span> (CONFIG_FEC_ENET_DEV == 0)</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> IMX_FEC_BASE			ENET_BASE_ADDR</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_FEC_MXC_PHYADDR          0x2</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_FEC_XCV_TYPE             RMII</span></span><br><span class="line"><span class="meta">#<span class="keyword">elif</span> (CONFIG_FEC_ENET_DEV == 1)</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> IMX_FEC_BASE			ENET2_BASE_ADDR</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_FEC_MXC_PHYADDR		0x1</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_FEC_XCV_TYPE		RMII</span></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_ETHPRIME			<span class="string">&quot;FEC&quot;</span></span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_PHYLIB</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_PHY_MICREL</span></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br></pre></td></tr></table></figure>

<p>宏 CONFIG_FEC_ENET_DEV 用于选择使用哪个网口，默认为 1，也就是选择ENET2。</p>
<p>宏CONFIG_FEC_MXC_PHYADDR 为 ENET1 的 PHY 地址，默认是 0X2，CONFIG_FEC_MXC_PHYADDR为 ENET2 的 PHY 地址，默认为 0x1。根据前面的分析可知，正点原子的 I.MX6U-ALPHA 开发板 ENET1 的 PHY 地址为0X0， ENET2 的 PHY 地址为 0X1，所以需要将第 335 行的宏 CONFIG_FEC_MXC_PHYADDR改为 0x0。</p>
<p>宏 CONFIG_PHY_MICREL 用于使能 uboot 中 Micrel 公司的 PHY驱动， KSZ8081 这颗 PHY 芯片就是 Micrel 公司生产的，不过 Micrel 已经被Microchip 收购了。如果要使用 LAN8720A，那么就得将 CONFIG_PHY_MICREL 改为 CONFIG_PHY_SMSC，也就是使能 uboot 中的 SMSC 公司中的 PHY 驱动，因为 LAN8720A 就是 SMSC 公司生产的。所以示例代码 上边的代码有三处要修改：</p>
<p>（1）修改 ENET1 网络 PHY 的地址。</p>
<p>（2）修改 ENET2 网络 PHY 的地址。</p>
<p>（3）使能 SMSC 公司的 PHY 驱动。</p>
<p>修改后的网络 PHY 地址参数如下所示：  </p>
<h4 id="3-2-2-删除-uboot-中-74LV595-的驱动代码"><a href="#3-2-2-删除-uboot-中-74LV595-的驱动代码" class="headerlink" title="3.2.2 删除 uboot 中 74LV595 的驱动代码  "></a><font size=3>3.2.2 删除 uboot 中 74LV595 的驱动代码  </font></h4><p>uboot 中网络 PHY 芯片地址修改完成以后就是网络复位引脚的驱动修改了，打开mx6ull_alpha_emmc.c，找到如下代码：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">define</span> IOX_SDI IMX_GPIO_NR(5, 10)</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> IOX_STCP IMX_GPIO_NR(5, 7)</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> IOX_SHCP IMX_GPIO_NR(5, 11)</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> IOX_OE IMX_GPIO_NR(5, 8)</span></span><br></pre></td></tr></table></figure>

<p>以 IOX 开头的宏定义是 74LV595 的相关 GPIO，因为 NXP 官方I.MX6ULL EVK 开发板使用 74LV595 来扩展 IO，两个网络的复位引脚就是由 74LV595 来控制的。正点原子的 I.MX6U-ALPHA 开发板并没有使用 74LV595，因此我们将上边的代码删除掉，替换为如下所示代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">define</span> ENET1_RESET IMX_GPIO_NR(5, 7)</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> ENET2_RESET IMX_GPIO_NR(5, 8)</span></span><br></pre></td></tr></table></figure>

<p>ENET1 的复位引脚连接到 SNVS_TAMPER7 上，对应 GPIO5_IO07， ENET2 的复位引脚连接到 SNVS_TAMPER8 上，对应 GPIO5_IO08。  继续在 mx6ull_alpha_emmc.c 中找到如下代码：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> <span class="type">iomux_v3_cfg_t</span> <span class="type">const</span> iox_pads[] = &#123;</span><br><span class="line">	<span class="comment">/* IOX_SDI */</span></span><br><span class="line">	MX6_PAD_BOOT_MODE0__GPIO5_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL),</span><br><span class="line">	<span class="comment">/* IOX_SHCP */</span></span><br><span class="line">	MX6_PAD_BOOT_MODE1__GPIO5_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),</span><br><span class="line">	<span class="comment">/* IOX_STCP */</span></span><br><span class="line">	MX6_PAD_SNVS_TAMPER7__GPIO5_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),</span><br><span class="line">	<span class="comment">/* IOX_nOE */</span></span><br><span class="line">	MX6_PAD_SNVS_TAMPER8__GPIO5_IO08 | MUX_PAD_CTRL(NO_PAD_CTRL),</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>这部分是74LV595 的 IO 配置参数结构体，将其删除掉。继续在mx6ull_alpha_emmc.c 中找到函数 iox74lv_init，如下所示：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> <span class="type">void</span> <span class="title function_">iox74lv_init</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">int</span> i;</span><br><span class="line"></span><br><span class="line">	gpio_direction_output(IOX_OE, <span class="number">0</span>);</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> (i = <span class="number">7</span>; i &gt;= <span class="number">0</span>; i--) &#123;</span><br><span class="line">		gpio_direction_output(IOX_SHCP, <span class="number">0</span>);</span><br><span class="line">		gpio_direction_output(IOX_SDI, seq[qn_output[i]][<span class="number">0</span>]);</span><br><span class="line">		udelay(<span class="number">500</span>);</span><br><span class="line">		gpio_direction_output(IOX_SHCP, <span class="number">1</span>);</span><br><span class="line">		udelay(<span class="number">500</span>);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	gpio_direction_output(IOX_STCP, <span class="number">0</span>);</span><br><span class="line">	udelay(<span class="number">500</span>);</span><br><span class="line">	<span class="comment">//......</span></span><br><span class="line">	udelay(<span class="number">500</span>);</span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">	 * shift register will be output to pins</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	gpio_direction_output(IOX_STCP, <span class="number">1</span>);</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>iox74lv_init 函数是 74LV595 的初始化函数 ，这个函数需要删除掉，继续在mx6ull_alpha_emmc.c 中找到函数 iox74lv_set  ，如下所示：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">iox74lv_set</span><span class="params">(<span class="type">int</span> index)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">int</span> i;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> (i = <span class="number">7</span>; i &gt;= <span class="number">0</span>; i--) &#123;</span><br><span class="line">		gpio_direction_output(IOX_SHCP, <span class="number">0</span>);</span><br><span class="line"></span><br><span class="line">		<span class="keyword">if</span> (i == index)</span><br><span class="line">			gpio_direction_output(IOX_SDI, seq[qn_output[i]][<span class="number">0</span>]);</span><br><span class="line">		<span class="keyword">else</span></span><br><span class="line">			gpio_direction_output(IOX_SDI, seq[qn_output[i]][<span class="number">1</span>]);</span><br><span class="line">		udelay(<span class="number">500</span>);</span><br><span class="line">		gpio_direction_output(IOX_SHCP, <span class="number">1</span>);</span><br><span class="line">		udelay(<span class="number">500</span>);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// ......</span></span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">	  * shift register will be output to pins</span></span><br><span class="line"><span class="comment">	  */</span></span><br><span class="line">	gpio_direction_output(IOX_STCP, <span class="number">1</span>);</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>iox74lv_set 函数用于控制 74LV595 的 IO 输出电平，这个函数也需要删除掉。 在 mx6ull_alpha_emmc.c 中找到 board_init 函数，此函数是板子初始化函数，会被board_init_r 调用， board_init 函数内容如下 ：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">board_init</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="comment">/* Address of boot parameters */</span></span><br><span class="line">	gd-&gt;bd-&gt;bi_boot_params = PHYS_SDRAM + <span class="number">0x100</span>;</span><br><span class="line">	imx_iomux_v3_setup_multiple_pads(iox_pads, ARRAY_SIZE(iox_pads));</span><br><span class="line">	iox74lv_init();</span><br><span class="line">	<span class="comment">// ......</span></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>board_init 会调用 imx_iomux_v3_setup_multiple_pads 和 iox74lv_init 这两个函数来初始化74lv595 的 GPIO，将这两行删除掉。至此，mx6ull_alpha_emmc.c 中关于 74LV595 芯片的驱动代码都删除掉了，接下来就是添加 I.MX6U-ALPHA 开发板两个网络复位引脚了。  </p>
<h4 id="3-2-3-添加-I-MX6U-ALPHA-开发板网络复位引脚驱动"><a href="#3-2-3-添加-I-MX6U-ALPHA-开发板网络复位引脚驱动" class="headerlink" title="3.2.3 添加 I.MX6U-ALPHA 开发板网络复位引脚驱动  "></a><font size=3>3.2.3 添加 I.MX6U-ALPHA 开发板网络复位引脚驱动  </font></h4><p>在 mx6ull_alpha_emmc.c 中找到如下所示代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> <span class="type">iomux_v3_cfg_t</span> <span class="type">const</span> fec1_pads[] = &#123;</span><br><span class="line">	MX6_PAD_GPIO1_IO06__ENET1_MDIO | MUX_PAD_CTRL(MDIO_PAD_CTRL),</span><br><span class="line">	MX6_PAD_GPIO1_IO07__ENET1_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_TX_DATA0__ENET1_TDATA00 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_TX_DATA1__ENET1_TDATA01 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_TX_EN__ENET1_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_TX_CLK__ENET1_REF_CLK1 | MUX_PAD_CTRL(ENET_CLK_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_RX_DATA0__ENET1_RDATA00 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_RX_DATA1__ENET1_RDATA01 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_RX_ER__ENET1_RX_ER | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_RX_EN__ENET1_RX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="type">static</span> <span class="type">iomux_v3_cfg_t</span> <span class="type">const</span> fec2_pads[] = &#123;</span><br><span class="line">	MX6_PAD_GPIO1_IO06__ENET2_MDIO | MUX_PAD_CTRL(MDIO_PAD_CTRL),</span><br><span class="line">	MX6_PAD_GPIO1_IO07__ENET2_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line"></span><br><span class="line">	MX6_PAD_ENET2_TX_DATA0__ENET2_TDATA00 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET2_TX_DATA1__ENET2_TDATA01 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET2_TX_CLK__ENET2_REF_CLK2 | MUX_PAD_CTRL(ENET_CLK_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET2_TX_EN__ENET2_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line"></span><br><span class="line">	MX6_PAD_ENET2_RX_DATA0__ENET2_RDATA00 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET2_RX_DATA1__ENET2_RDATA01 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET2_RX_EN__ENET2_RX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET2_RX_ER__ENET2_RX_ER | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>结构体数组 fec1_pads 和 fec2_pads 是 ENET1 和 ENET2 这两个网口的 IO 配置参数，在这两个数组中添加两个网口的复位 IO 配置参数，完成以后如下所示：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* ENET1 网口 IO 配置参数</span></span><br><span class="line"><span class="comment"> * pin conflicts for fec1 and fec2, GPIO1_IO06 and GPIO1_IO07 can only</span></span><br><span class="line"><span class="comment"> * be used for ENET1 or ENET2, cannot be used for both.</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="type">static</span> <span class="type">iomux_v3_cfg_t</span> <span class="type">const</span> fec1_pads[] = &#123;</span><br><span class="line">	MX6_PAD_GPIO1_IO06__ENET1_MDIO | MUX_PAD_CTRL(MDIO_PAD_CTRL),</span><br><span class="line">	MX6_PAD_GPIO1_IO07__ENET1_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_TX_DATA0__ENET1_TDATA00 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_TX_DATA1__ENET1_TDATA01 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_TX_EN__ENET1_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_TX_CLK__ENET1_REF_CLK1 | MUX_PAD_CTRL(ENET_CLK_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_RX_DATA0__ENET1_RDATA00 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_RX_DATA1__ENET1_RDATA01 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_RX_ER__ENET1_RX_ER | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET1_RX_EN__ENET1_RX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_SNVS_TAMPER7__GPIO5_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),</span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment">/* ENET2 网口 IO 配置参数 */</span></span><br><span class="line"><span class="type">static</span> <span class="type">iomux_v3_cfg_t</span> <span class="type">const</span> fec2_pads[] = &#123;</span><br><span class="line">	MX6_PAD_GPIO1_IO06__ENET2_MDIO | MUX_PAD_CTRL(MDIO_PAD_CTRL),</span><br><span class="line">	MX6_PAD_GPIO1_IO07__ENET2_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line"></span><br><span class="line">	MX6_PAD_ENET2_TX_DATA0__ENET2_TDATA00 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET2_TX_DATA1__ENET2_TDATA01 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET2_TX_CLK__ENET2_REF_CLK2 | MUX_PAD_CTRL(ENET_CLK_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET2_TX_EN__ENET2_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line"></span><br><span class="line">	MX6_PAD_ENET2_RX_DATA0__ENET2_RDATA00 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET2_RX_DATA1__ENET2_RDATA01 | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET2_RX_EN__ENET2_RX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_ENET2_RX_ER__ENET2_RX_ER | MUX_PAD_CTRL(ENET_PAD_CTRL),</span><br><span class="line">	MX6_PAD_SNVS_TAMPER8__GPIO5_IO08 | MUX_PAD_CTRL(NO_PAD_CTRL),</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>继续在文件 mx6ull_alpha_emmc.c 中找到函数 setup_iomux_fec，此函数默认代码如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> <span class="type">void</span> <span class="title function_">setup_iomux_fec</span><span class="params">(<span class="type">int</span> fec_id)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">if</span> (fec_id == <span class="number">0</span>)</span><br><span class="line">		imx_iomux_v3_setup_multiple_pads(fec1_pads,</span><br><span class="line">						 ARRAY_SIZE(fec1_pads));</span><br><span class="line">	<span class="keyword">else</span></span><br><span class="line">		imx_iomux_v3_setup_multiple_pads(fec2_pads,</span><br><span class="line">						 ARRAY_SIZE(fec2_pads));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>  修改后如下所示：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> <span class="type">void</span> <span class="title function_">setup_iomux_fec</span><span class="params">(<span class="type">int</span> fec_id)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">if</span> (fec_id == <span class="number">0</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		imx_iomux_v3_setup_multiple_pads(fec1_pads, ARRAY_SIZE(fec1_pads));</span><br><span class="line">		<span class="comment">/* ENET1的复位 IO初始化，将这两个IO设置为输出并且硬件复位一下 LAN8720A，这个硬件复位很重要否则可能导致 uboot无法识别 LAN8720A。 */</span></span><br><span class="line">		gpio_direction_output(ENET1_RESET, <span class="number">1</span>);</span><br><span class="line">		gpio_set_value(ENET1_RESET, <span class="number">0</span>);</span><br><span class="line">		mdelay(<span class="number">20</span>);</span><br><span class="line">		gpio_set_value(ENET1_RESET, <span class="number">1</span>);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">else</span></span><br><span class="line">	&#123;</span><br><span class="line">		imx_iomux_v3_setup_multiple_pads(fec2_pads, ARRAY_SIZE(fec2_pads));</span><br><span class="line">		<span class="comment">/* ENET2的复位 IO初始化，将这两个IO设置为输出并且硬件复位一下 LAN8720A，这个硬件复位很重要否则可能导致 uboot无法识别 LAN8720A。 */</span></span><br><span class="line">		gpio_direction_output(ENET2_RESET, <span class="number">1</span>);</span><br><span class="line">		gpio_set_value(ENET2_RESET, <span class="number">0</span>);</span><br><span class="line">		mdelay(<span class="number">20</span>);</span><br><span class="line">		gpio_set_value(ENET2_RESET, <span class="number">1</span>);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>新增加的部分分别对应 ENET1 和 ENET2 的复位 IO 初始化，将这两个 IO 设置为输出并且硬件复位一下 LAN8720A，这个硬件复位很重要！否则可能导致 uboot 无法识别 LAN8720A。  </p>
<h4 id="3-2-4-修改函数-genphy-update-link"><a href="#3-2-4-修改函数-genphy-update-link" class="headerlink" title="3.2.4 修改函数 genphy_update_link  "></a><font size=3>3.2.4 修改函数 genphy_update_link  </font></h4><p>这个函数位于 drivers&#x2F;net&#x2F;phy&#x2F;phy.c 文件中，这是个通用 PHY 驱动函数，此函数用于更新 PHY 的连接状态和速度。使用 LAN8720A 的时候需要在此函数中添加一些代码，修改后的函数 genphy_update_link 如下所示：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * genphy_update_link - update link status in @phydev</span></span><br><span class="line"><span class="comment"> * @phydev: target phy_device struct</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * Description: Update the value in phydev-&gt;link to reflect the</span></span><br><span class="line"><span class="comment"> *   current link value.  In order to do this, we need to read</span></span><br><span class="line"><span class="comment"> *   the status register twice, keeping the second value.</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="type">int</span> <span class="title function_">genphy_update_link</span><span class="params">(<span class="keyword">struct</span> phy_device *phydev)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">unsigned</span> <span class="type">int</span> mii_reg;</span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> CONFIG_PHY_SMSC</span></span><br><span class="line">	<span class="comment">/* 条件编译代码段，只有使用 SMSC公司的 PHY这段代码才会执行 */</span></span><br><span class="line">	<span class="type">static</span> <span class="type">int</span> lan8720_flag = <span class="number">0</span>;</span><br><span class="line">	<span class="type">int</span> bmcr_reg = <span class="number">0</span>;</span><br><span class="line">	<span class="keyword">if</span> (lan8720_flag == <span class="number">0</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		bmcr_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);  <span class="comment">/* 读取LAN8720A的 BMCR寄存器 (寄存器地址为 0)，此寄存器为LAN8720A的配置寄存器，这里先读取此寄存器的默认值并保存起来。 */</span></span><br><span class="line">		phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET);<span class="comment">/* 向寄存器BMCR寄存器写入BMCR_RESET(值为0X8000)，因为BMCR的 bit15是软件复位控制位，复位完成以后此位会自动清零。*/</span></span><br><span class="line">		<span class="comment">/* 等待 LAN8720A软件复位完成，也就是判断 BMCR的 bit15位是否为 1，为 1的话表示还没有复位完成。*/</span></span><br><span class="line">		<span class="keyword">while</span>(phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR) &amp; <span class="number">0X8000</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			udelay(<span class="number">100</span>);</span><br><span class="line">		&#125;</span><br><span class="line">		phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, bmcr_reg); <span class="comment">/* 重新向 BMCR寄存器写入以前的值，也就是前边读出的那个值。 */</span></span><br><span class="line">		lan8720_flag = <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">	 * Wait if the link is up, and autonegotiation is in progress</span></span><br><span class="line"><span class="comment">	 * (ie - we&#x27;re capable and it&#x27;s not done)</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);</span><br><span class="line"></span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">	 * If we already saw the link up, and it hasn&#x27;t gone down, then</span></span><br><span class="line"><span class="comment">	 * we don&#x27;t need to wait for autoneg again</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	<span class="keyword">if</span> (phydev-&gt;link &amp;&amp; mii_reg &amp; BMSR_LSTATUS)</span><br><span class="line">		<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">if</span> ((phydev-&gt;autoneg == AUTONEG_ENABLE) &amp;&amp;</span><br><span class="line">	    !(mii_reg &amp; BMSR_ANEGCOMPLETE)) &#123;</span><br><span class="line">		<span class="type">int</span> i = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">		<span class="built_in">printf</span>(<span class="string">&quot;%s Waiting for PHY auto negotiation to complete&quot;</span>,</span><br><span class="line">			phydev-&gt;dev-&gt;name);</span><br><span class="line">		<span class="keyword">while</span> (!(mii_reg &amp; BMSR_ANEGCOMPLETE)) &#123;</span><br><span class="line">			<span class="comment">/*</span></span><br><span class="line"><span class="comment">			 * Timeout reached ?</span></span><br><span class="line"><span class="comment">			 */</span></span><br><span class="line">			<span class="keyword">if</span> (i &gt; PHY_ANEG_TIMEOUT) &#123;</span><br><span class="line">				<span class="built_in">printf</span>(<span class="string">&quot; TIMEOUT !\n&quot;</span>);</span><br><span class="line">				phydev-&gt;link = <span class="number">0</span>;</span><br><span class="line">				<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			<span class="keyword">if</span> (ctrlc()) &#123;</span><br><span class="line">				<span class="built_in">puts</span>(<span class="string">&quot;user interrupt!\n&quot;</span>);</span><br><span class="line">				phydev-&gt;link = <span class="number">0</span>;</span><br><span class="line">				<span class="keyword">return</span> -EINTR;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			<span class="keyword">if</span> ((i++ % <span class="number">500</span>) == <span class="number">0</span>)</span><br><span class="line">				<span class="built_in">printf</span>(<span class="string">&quot;.&quot;</span>);</span><br><span class="line"></span><br><span class="line">			udelay(<span class="number">1000</span>);	<span class="comment">/* 1 ms */</span></span><br><span class="line">			mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">printf</span>(<span class="string">&quot; done\n&quot;</span>);</span><br><span class="line">		phydev-&gt;link = <span class="number">1</span>;</span><br><span class="line">	&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">		<span class="comment">/* Read the link a second time to clear the latched state */</span></span><br><span class="line">		mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);</span><br><span class="line"></span><br><span class="line">		<span class="keyword">if</span> (mii_reg &amp; BMSR_LSTATUS)</span><br><span class="line">			phydev-&gt;link = <span class="number">1</span>;</span><br><span class="line">		<span class="keyword">else</span></span><br><span class="line">			phydev-&gt;link = <span class="number">0</span>;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="3-3-编译下载测试"><a href="#3-3-编译下载测试" class="headerlink" title="3.3 编译下载测试"></a><font size=3>3.3 编译下载测试</font></h3><p>我们编译好后下载到SD卡中，将会有如下打印信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730224023173.png" alt="image-20230730224023173" style="zoom:50%;" />

<p>我们发现看到有“Net： FEC1”这一行，提示当前使用的 FEC1 这个网口，也就是 ENET2。 但下边紧跟着就报错啦，说是地址没设置，那我们设置一下就好啦：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">=&gt; setenv ipaddr 192.168.10.109     # 开发板 IP 地址</span><br><span class="line">=&gt; setenv ethaddr b8:ae:1d:01:00:01 # 开发板网卡 MAC 地址</span><br><span class="line">=&gt; setenv gatewayip 192.168.10.1    # 开发板默认网关</span><br><span class="line">=&gt; setenv netmask 255.255.255.0     # 开发板子网掩码</span><br><span class="line">=&gt; saveenv</span><br><span class="line">=&gt; print ipaddr ethaddr gatewayip netmask</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730224146997.png" alt="image-20230730224146997" style="zoom:50%;" />

<p>设置好环境变量以后就可以在 uboot 中使用网络了，可以发现设置完IP后，这里就不再报错了：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730224659211.png" alt="image-20230730224659211" style="zoom:50%;" />

<p>用网线将 I.MX6U-ALPHA 上的 ENET2 与电脑或者路由器连接起来，保证开发板和电脑在同一个网段内，通过 ping 命令来测试一下网络连接，命令如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ping 192.168.10.100</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230730230203861.png" alt="image-20230730230203861" style="zoom:50%;" />

<p>需要注意的是，由于我用的是扩展坞扩展的网口，经常会出现通信失败的情况，要是出现的话，我们可以在windows下重启一下这个网口，一般就可以了，可以win+r调出运行框，然后输入以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ncpa.cpl</span><br></pre></td></tr></table></figure>

<p>然后就会打开控制界面，我可以双击扩展的以太网口，进行禁用，然后重新启动即可。</p>
<h2 id="4-其他修改"><a href="#4-其他修改" class="headerlink" title="4. 其他修改"></a><font size=3>4. 其他修改</font></h2><p>在 uboot 启动信息中会有“Board: MX6ULL 14x14 EVK”这一句，也就是说板子名字为“ MX6ULL 14x14 EVK”，要将其改为我们所使用的板子名字，比如“ MX6ULL ALPHA EMMC”或者“MX6ULL ALPHA NAND”。打开文件 mx6ull_alpha_emmc.c，找到函数checkboard，将其改为如下所示内容： </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">checkboard</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">if</span> (is_mx6ull_9x9_evk())</span><br><span class="line">		<span class="built_in">puts</span>(<span class="string">&quot;Board: MX6ULL 9x9 EVK\n&quot;</span>);</span><br><span class="line">	<span class="keyword">else</span></span><br><span class="line">		<span class="built_in">puts</span>(<span class="string">&quot;Board: MX6ULL ALPHA EMMC(8GB)\n&quot;</span>);</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p> 然后重新编译烧写，重启后就会发现这里已经被修改为我们想要的样子啦：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230731162034012.png" alt="image-20230731162034012" style="zoom:50%;" />

<h1 id="三、bootcmd与bootargs"><a href="#三、bootcmd与bootargs" class="headerlink" title="三、bootcmd与bootargs"></a><font size=3>三、bootcmd与bootargs</font></h1><h2 id="1-概述"><a href="#1-概述" class="headerlink" title="1. 概述"></a><font size=3>1. 概述</font></h2><p>uboot 中有两个非常重要的环境变量 bootcmd 和 bootargs，接下来看一下这两个环境变量。bootcmd 和 bootagrs 是采用类似 shell 脚本语言编写的，里面有很多的变量引用，这些变量其实都是环境变量，有很多是NXP自己定义的 。文件 mx6ull_alpha_emmc.h 中的宏CONFIG_EXTRA_ENV_SETTINGS 保存着这些环境变量的默认值，内容如下：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_MFG_ENV_SETTINGS \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;mfgtool_args=setenv bootargs console=$&#123;console&#125;,$&#123;baudrate&#125; &quot;</span> \</span></span><br><span class="line"><span class="meta">	    CONFIG_BOOTARGS_CMA_SIZE \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;rdinit=/linuxrc &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;g_mass_storage.stall=0 g_mass_storage.removable=1 &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;g_mass_storage.file=/fat g_mass_storage.ro=1 &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;g_mass_storage.idVendor=0x066F g_mass_storage.idProduct=0x37FF &quot;</span>\</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;g_mass_storage.iSerialNumber=\&quot;\&quot; &quot;</span>\</span></span><br><span class="line"><span class="meta">		CONFIG_MFG_NAND_PARTITION \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;clk_ignore_unused &quot;</span>\</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;initrd_addr=0x83800000\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;initrd_high=0xffffffff\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;bootcmd_mfg=run mfgtool_args;bootz $&#123;loadaddr&#125; $&#123;initrd_addr&#125; $&#123;fdt_addr&#125;;\0&quot;</span> \</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#<span class="keyword">if</span> defined(CONFIG_SYS_BOOT_NAND)</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_EXTRA_ENV_SETTINGS \</span></span><br><span class="line"><span class="meta">	CONFIG_MFG_ENV_SETTINGS \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;panel=ATK-LCD-4.3-800x480\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;fdt_addr=0x83000000\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;fdt_high=0xffffffff\0&quot;</span>	  \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;console=ttymxc0\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;bootargs=console=ttymxc0,115200 ubi.mtd=4 &quot;</span>  \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;root=ubi0:rootfs rootfstype=ubifs &quot;</span>		     \</span></span><br><span class="line"><span class="meta">		CONFIG_BOOTARGS_CMA_SIZE \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;mtdparts=gpmi-nand:64m(boot),16m(kernel),16m(dtb),1m(misc),-(rootfs)\0&quot;</span>\</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;bootcmd=nand read $&#123;loadaddr&#125; 0x4000000 0x800000;&quot;</span>\</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;nand read $&#123;fdt_addr&#125; 0x5000000 0x100000;&quot;</span>\</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;bootz $&#123;loadaddr&#125; - $&#123;fdt_addr&#125;\0&quot;</span></span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">else</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_EXTRA_ENV_SETTINGS \</span></span><br><span class="line"><span class="meta">	CONFIG_MFG_ENV_SETTINGS \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;script=boot.scr\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;image=zImage\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;console=ttymxc0\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;fdt_high=0xffffffff\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;initrd_high=0xffffffff\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;fdt_file=undefined\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;fdt_addr=0x83000000\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;boot_fdt=try\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;ip_dyn=yes\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;panel=ATK-LCD-4.3-800x480\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;mmcdev=&quot;</span>__stringify(CONFIG_SYS_MMC_ENV_DEV)<span class="string">&quot;\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;mmcpart=&quot;</span> __stringify(CONFIG_SYS_MMC_IMG_LOAD_PART) <span class="string">&quot;\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;mmcroot=&quot;</span> CONFIG_MMCROOT <span class="string">&quot; rootwait rw\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;mmcautodetect=yes\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;mmcargs=setenv bootargs console=$&#123;console&#125;,$&#123;baudrate&#125; &quot;</span> \</span></span><br><span class="line"><span class="meta">		CONFIG_BOOTARGS_CMA_SIZE \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;root=$&#123;mmcroot&#125;\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;loadbootscript=&quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;fatload mmc $&#123;mmcdev&#125;:$&#123;mmcpart&#125; $&#123;loadaddr&#125; $&#123;script&#125;;\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;bootscript=echo Running bootscript from mmc ...; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;source\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;loadimage=fatload mmc $&#123;mmcdev&#125;:$&#123;mmcpart&#125; $&#123;loadaddr&#125; $&#123;image&#125;\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;loadfdt=fatload mmc $&#123;mmcdev&#125;:$&#123;mmcpart&#125; $&#123;fdt_addr&#125; $&#123;fdt_file&#125;\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;mmcboot=echo Booting from mmc ...; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;run mmcargs; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;if test $&#123;boot_fdt&#125; = yes || test $&#123;boot_fdt&#125; = try; then &quot;</span> \</span></span><br><span class="line"><span class="meta">			<span class="string">&quot;if run loadfdt; then &quot;</span> \</span></span><br><span class="line"><span class="meta">				<span class="string">&quot;bootz $&#123;loadaddr&#125; - $&#123;fdt_addr&#125;; &quot;</span> \</span></span><br><span class="line"><span class="meta">			<span class="string">&quot;else &quot;</span> \</span></span><br><span class="line"><span class="meta">				<span class="string">&quot;if test $&#123;boot_fdt&#125; = try; then &quot;</span> \</span></span><br><span class="line"><span class="meta">					<span class="string">&quot;bootz; &quot;</span> \</span></span><br><span class="line"><span class="meta">				<span class="string">&quot;else &quot;</span> \</span></span><br><span class="line"><span class="meta">					<span class="string">&quot;echo WARN: Cannot load the DT; &quot;</span> \</span></span><br><span class="line"><span class="meta">				<span class="string">&quot;fi; &quot;</span> \</span></span><br><span class="line"><span class="meta">			<span class="string">&quot;fi; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;else &quot;</span> \</span></span><br><span class="line"><span class="meta">			<span class="string">&quot;bootz; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;fi;\0&quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;netargs=setenv bootargs console=$&#123;console&#125;,$&#123;baudrate&#125; &quot;</span> \</span></span><br><span class="line"><span class="meta">		CONFIG_BOOTARGS_CMA_SIZE \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;root=/dev/nfs &quot;</span> \</span></span><br><span class="line"><span class="meta">	<span class="string">&quot;ip=dhcp nfsroot=$&#123;serverip&#125;:$&#123;nfsroot&#125;,v3,tcp\0&quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;netboot=echo Booting from net ...; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;run netargs; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;if test $&#123;ip_dyn&#125; = yes; then &quot;</span> \</span></span><br><span class="line"><span class="meta">			<span class="string">&quot;setenv get_cmd dhcp; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;else &quot;</span> \</span></span><br><span class="line"><span class="meta">			<span class="string">&quot;setenv get_cmd tftp; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;fi; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;$&#123;get_cmd&#125; $&#123;image&#125;; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;if test $&#123;boot_fdt&#125; = yes || test $&#123;boot_fdt&#125; = try; then &quot;</span> \</span></span><br><span class="line"><span class="meta">			<span class="string">&quot;if $&#123;get_cmd&#125; $&#123;fdt_addr&#125; $&#123;fdt_file&#125;; then &quot;</span> \</span></span><br><span class="line"><span class="meta">				<span class="string">&quot;bootz $&#123;loadaddr&#125; - $&#123;fdt_addr&#125;; &quot;</span> \</span></span><br><span class="line"><span class="meta">			<span class="string">&quot;else &quot;</span> \</span></span><br><span class="line"><span class="meta">				<span class="string">&quot;if test $&#123;boot_fdt&#125; = try; then &quot;</span> \</span></span><br><span class="line"><span class="meta">					<span class="string">&quot;bootz; &quot;</span> \</span></span><br><span class="line"><span class="meta">				<span class="string">&quot;else &quot;</span> \</span></span><br><span class="line"><span class="meta">					<span class="string">&quot;echo WARN: Cannot load the DT; &quot;</span> \</span></span><br><span class="line"><span class="meta">				<span class="string">&quot;fi; &quot;</span> \</span></span><br><span class="line"><span class="meta">			<span class="string">&quot;fi; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;else &quot;</span> \</span></span><br><span class="line"><span class="meta">			<span class="string">&quot;bootz; &quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;fi;\0&quot;</span> \</span></span><br><span class="line"><span class="meta">		<span class="string">&quot;findfdt=&quot;</span>\</span></span><br><span class="line"><span class="meta">			<span class="string">&quot;if test $fdt_file = undefined; then &quot;</span> \</span></span><br><span class="line"><span class="meta">				<span class="string">&quot;if test $board_name = EVK &amp;&amp; test $board_rev = 9X9; then &quot;</span> \</span></span><br><span class="line"><span class="meta">					<span class="string">&quot;setenv fdt_file imx6ull-9x9-evk.dtb; fi; &quot;</span> \</span></span><br><span class="line"><span class="meta">				<span class="string">&quot;if test $board_name = EVK &amp;&amp; test $board_rev = 14X14; then &quot;</span> \</span></span><br><span class="line"><span class="meta">					<span class="string">&quot;setenv fdt_file imx6ull-14x14-evk.dtb; fi; &quot;</span> \</span></span><br><span class="line"><span class="meta">				<span class="string">&quot;if test $fdt_file = undefined; then &quot;</span> \</span></span><br><span class="line"><span class="meta">					<span class="string">&quot;echo WARNING: Could not determine dtb to use; fi; &quot;</span> \</span></span><br><span class="line"><span class="meta">			<span class="string">&quot;fi;\0&quot;</span> \</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_BOOTCOMMAND \</span></span><br><span class="line"><span class="meta">	   <span class="string">&quot;run findfdt;&quot;</span> \</span></span><br><span class="line"><span class="meta">	   <span class="string">&quot;mmc dev $&#123;mmcdev&#125;;&quot;</span> \</span></span><br><span class="line"><span class="meta">	   <span class="string">&quot;mmc dev $&#123;mmcdev&#125;; if mmc rescan; then &quot;</span> \</span></span><br><span class="line"><span class="meta">		   <span class="string">&quot;if run loadbootscript; then &quot;</span> \</span></span><br><span class="line"><span class="meta">			   <span class="string">&quot;run bootscript; &quot;</span> \</span></span><br><span class="line"><span class="meta">		   <span class="string">&quot;else &quot;</span> \</span></span><br><span class="line"><span class="meta">			   <span class="string">&quot;if run loadimage; then &quot;</span> \</span></span><br><span class="line"><span class="meta">				   <span class="string">&quot;run mmcboot; &quot;</span> \</span></span><br><span class="line"><span class="meta">			   <span class="string">&quot;else run netboot; &quot;</span> \</span></span><br><span class="line"><span class="meta">			   <span class="string">&quot;fi; &quot;</span> \</span></span><br><span class="line"><span class="meta">		   <span class="string">&quot;fi; &quot;</span> \</span></span><br><span class="line"><span class="meta">	   <span class="string">&quot;else run netboot; fi&quot;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br></pre></td></tr></table></figure>

<p>宏 CONFIG_EXTRA_ENV_SETTINGS 是个条件编译语句，使用 NAND 和 EMMC 的时候宏 CONFIG_EXTRA_ENV_SETTINGS 的值是不同的。  </p>
<h2 id="2-bootcmd"><a href="#2-bootcmd" class="headerlink" title="2. bootcmd"></a><font size=3>2. bootcmd</font></h2><p>bootcmd 保存着 uboot 默认命令， uboot 倒计时结束以后就会执行 bootcmd 中的命令。这些命令一般都是用来启动 Linux 内核的，比如读取 EMMC 或者 NAND Flash 中的 Linux 内核镜像文件和设备树文件到 DRAM 中，然后启动 Linux 内核。可以在 uboot 启动以后进入命令行设置 bootcmd 环境变量的值。如果 EMMC 或者 NAND 中没有保存 bootcmd 的值，那么 uboot 就会使用默认的值，板子第一次运行 uboot 的时候都会使用默认值来设置 bootcmd 环境变量。打开文件 include&#x2F;env_default.h，在此文件中有如下所示内容  ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230731162611666.png" alt="image-20230731162611666" style="zoom:50%;" />

<p>第 13~23 行 ， 这段代码是个条件编译， 由于没有定义DEFAULT_ENV_INSTANCE_EMBEDDED 和 CONFIG_SYS_REDUNDAND_ENVIRONMENT，因此 uchar default_environment[]数组保存环境变量。  </p>
<p>default_environment数组中指定了很多环境变量的默认值，比如 bootcmd 的默认值就是CONFIG_BOOTCOMMAND， bootargs 的默认值就是 CONFIG_BOOTARGS。我们可以在mx6ull_alphak_emmc.h 文件中通过设置宏 CONFIG_BOOTCOMMAND 来设置 bootcmd 的默认值， NXP 官方设置的 CONFIG_BOOTCOMMAND 值如下：  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230731162842324.png" alt="image-20230731162842324" style="zoom:50%;" />

<p>第 207 行， run findfdt；使用的是 uboot 的 run 命令来运行 findfdt， findfdt 是 NXP 自行添加的环境变量。 findfdt 是用来查找开发板对应的设备树文件(.dtb)。 IMX6ULL EVK 的设备树文件为 imx6ull-14x14-evk.dtb， findfdt（mx6ull_alphak_emmc.h文件中） 内容如下：  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230731163050919.png" alt="image-20230731163050919" style="zoom:50%;" />

<p>findfdt 里面用到的变量有 fdt_file， board_name， board_rev，这三个变量内容如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">fdt_file=undefined， board_name=EVK， board_rev=14X14</span><br></pre></td></tr></table></figure>

<p>findfdt 做的事情就是判断， fdt_file 是否为 undefined，如果 fdt_file 为 undefined 的话那就要根据板子信息得出所需的.dtb 文件名。此时 fdt_file为 undefined，所以根据 board_name 和board_rev 来判断实际所需的.dtb 文件，如果 board_name 为 EVK 并且 board_rev&#x3D;9x9 的话 fdt_file就为 imx6ull-9x9-evk.dtb。如果 board_name 为 EVK 并且 board_rev&#x3D;14x14 的话 fdt_file 就设置为 imx6ull-14x14-evk.dtb。因此 IMX6ULL EVK 板子的设备树文件就是 imx6ull-14x14-evk.dtb，因此 run findfdt 的结果就是设置 fdt_file 为 imx6ull-14x14-evk.dtb。 </p>
<p>第 208 行， mmc dev ${mmcdev}用于切换 mmc 设备， mmcdev 为 1，因此这行代码就是： mmcdev 1，也就是切换到 EMMC 上。  </p>
<p>第 209 行，先执行 mmc dev ${mmcdev}切换到 EMMC 上，然后使用命令 mmc rescan 扫描看有没有 SD 卡或者 EMMC 存在，如果没有的话就直接跳到 218 行，执行 run netboot， netboot也是一个自定义的环境变量，这个变量是从网络启动 Linux 的。如果 mmc 设备存在的话就从mmc 设备启动。<br>第 210 行， 运行 loadbootscript 环境变量，此环境变量内容如下：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">loadbootscript=fatload mmc $&#123;mmcdev&#125;:$&#123;mmcpart&#125; $&#123;loadaddr&#125; $&#123;script&#125;;</span><br></pre></td></tr></table></figure>

<p>其中 mmcdev&#x3D;1， mmcpart&#x3D;1， loadaddr&#x3D;0x80800000， script&#x3D; boot.scr，因此展开以后就是：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">loadbootscript=fatload mmc 1:1 0x80800000 boot.scr;</span><br></pre></td></tr></table></figure>

<p>loadbootscript 就是从 mmc1 的分区 1 中读取文件 boot.src 到 DRAM 的 0X80800000 处。但是 mmc1 的分区 1 中没有 boot.src 这个文件，可以使用命令“ls mmc 1:1”查看一下 mmc1 分区 1 中的所有文件，看看有没有 boot.src 这个文件。  </p>
<p>第 211 行， 如果加载 boot.src 文件成功的话就运行 bootscript 环境变量， bootscript 的内容如下 :</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">bootscript=echo Running bootscript from mmc ...;</span><br><span class="line">source</span><br></pre></td></tr></table></figure>

<p>因为 boot.src 文件不存在，所以 bootscript 也就不会运行。  </p>
<p>第 213 行， 如果 loadbootscript 没有找到 boot.src 的话就运行环境变量 loadimage，环境变量loadimage 内容如下：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">loadimage=fatload mmc $&#123;mmcdev&#125;:$&#123;mmcpart&#125; $&#123;loadaddr&#125; $&#123;image&#125;</span><br></pre></td></tr></table></figure>

<p>其中 mmcdev&#x3D;1， mmcpart&#x3D;1， loadaddr&#x3D;0x80800000， image &#x3D; zImage， 展开以后就是：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">loadimage=fatload mmc 1:1 0x80800000 zImage</span><br></pre></td></tr></table></figure>

<p>可以看出 loadimage 就是从 mmc1 的分区中读取 zImage 到内存的 0X80800000 处，而 mmc1 的分区 1 中存在 zImage。  </p>
<p>第 212 行， 加载 linux 镜像文件 zImage 成功以后就运行环境变量 mmcboot，否则的话运行 netboot 环境变量。 </p>
<details class="folding-tag" blue><summary> 点击查看 netboot </summary>
              <div class='content'>
              <p>mmcboot 环境变量如下：  </p><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/LV05-01-uboot-07-uboot%E7%A7%BB%E6%A4%8D/img/image-20230731163602889.png" alt="image-20230731163602889" style="zoom:50%;" /><p>第 156 行， 输出信息“Booting from mmc …”。</p><p>第 157 行， 运行环境变量 mmcargs， mmcargs 用来设置 bootargs，后面分析 bootargs 的时候在学习。</p><p>第 158 行， 判断boot_fdt是否为yes或者try，根据uboot输出的环境变量信息可知boot_fdt&#x3D;try。因此会执行 159 行的语句。</p><p>第 159 行， 运行环境变量 loadfdt，环境变量 loadfdt 定义如下：</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">loadfdt=fatload mmc $&#123;mmcdev&#125;:$&#123;mmcpart&#125; $&#123;fdt_addr&#125; $&#123;fdt_file&#125;</span><br></pre></td></tr></table></figure><p>展开以后就是：</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">loadfdt=fatload mmc 1:1 0x83000000 imx6ull-14x14-evk.dtb</span><br></pre></td></tr></table></figure><p>因此 loadfdt 的作用就是从 mmc1 的分区 1 中读取 imx6ull-14x14-evk.dtb 文件并放到 0x83000000处。</p><p>第 160 行，如果读取.dtb 文件成功的话那就调用命令 bootz 启动 linux，调用方法如下：  </p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bootz $&#123;loadaddr&#125; - $&#123;fdt_addr&#125;;</span><br></pre></td></tr></table></figure><p>展开就是：</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bootz 0x80800000 - 0x83000000 (注意‘-’前后要有空格)  </span><br></pre></td></tr></table></figure>
              </div>
            </details>

<p>至此 Linux 内核启动，如此复杂的设置就是为了从 EMMC 中读取 zImage 镜像文件和设备树文件。经过分析，浓缩出来的仅仅是 4 行精华：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">mmc dev 1                         # 切换到 EMMC</span><br><span class="line">fatload mmc 1:1 0x80800000 zImage # 读取 zImage 到 0x80800000 处</span><br><span class="line">fatload mmc 1:1 0x83000000 imx6ull-14x14-evk.dtb # 读取设备树到 0x83000000 处</span><br><span class="line">bootz 0x80800000 - 0x83000000     # 启动 Linux</span><br></pre></td></tr></table></figure>

<p>NXP 官方将 CONFIG_BOOTCOMMAND 写的这么复杂只有一个目的：为了兼容多个板子，所以写了个很复杂的脚本。当我们明确知道我们所使用的板子的时候就可以大幅简化宏CONFIG_BOOTCOMMAND 的 设 置 ， 比如我们要从EMMC 启 动 ， 那么宏CONFIG_BOOTCOMMAND 就可简化为：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">define</span> CONFIG_BOOTCOMMAND \</span></span><br><span class="line"><span class="meta">    <span class="string">&quot;mmc dev 1;&quot;</span> \</span></span><br><span class="line"><span class="meta">    <span class="string">&quot;fatload mmc 1:1 0x80800000 zImage;&quot;</span> \</span></span><br><span class="line"><span class="meta">    <span class="string">&quot;fatload mmc 1:1 0x83000000 imx6ull-14x14-evk.dtb;&quot;</span> \</span></span><br><span class="line"><span class="meta">    <span class="string">&quot;bootz 0x80800000 - 0x83000000;&quot;</span></span></span><br></pre></td></tr></table></figure>

<p>或者可以直接在 uboot 中设置 bootcmd 的值，这个值就是保存到 EMMC 中的，命令如下：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">setenv bootcmd &#x27;mmc dev 1; fatload mmc 1:1 80800000 zImage; fatload mmc 1:1 83000000 imx6ull-14x14-evk.dtb;bootz 80800000 - 83000000;</span><br></pre></td></tr></table></figure>

<h2 id="3-bootargs"><a href="#3-bootargs" class="headerlink" title="3. bootargs"></a><font size=3>3. bootargs</font></h2><p>bootargs 保存着 uboot 传递给 Linux 内核的参数，在上一小节讲解 bootcmd 的时候说过，bootargs 环境变量是由 mmcargs 设置的， mmcargs 环境变量如下：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mmcargs=setenv bootargs console=$&#123;console&#125;,$&#123;baudrate&#125; root=$&#123;mmcroot&#125;</span><br></pre></td></tr></table></figure>

<p>其中 console&#x3D;ttymxc0， baudrate&#x3D;115200， mmcroot&#x3D;&#x2F;dev&#x2F;mmcblk1p2 rootwait rw，因此将mmcargs 展开以后就是：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mmcargs=setenv bootargs console= ttymxc0, 115200 root= /dev/mmcblk1p2 rootwait rw</span><br></pre></td></tr></table></figure>

<p>可以看出环境变量 mmcargs 就是设置 bootargs 的值为“ console&#x3D; ttymxc0, 115200 root&#x3D;&#x2F;dev&#x2F;mmcblk1p2 rootwait rw”， bootargs 就是设置了很多的参数的值，这些参数 Linux 内核会使用到，常用的参数有：  </p>
<ul>
<li>（1）console</li>
</ul>
<p>console 用来设置 linux 终端(或者叫控制台)，也就是通过什么设备来和 Linux 进行交互，是串口还是 LCD 屏幕？如果是串口的话应该是串口几等等。一般设置串口作为 Linux 终端，这样我们就可以在电脑上通过 SecureCRT 来和 linux 交互了。这里设置 console 为 ttymxc0，因为 linux启动以后I.MX6ULL 的串口 1 在 linux 下的设备文件就是&#x2F;dev&#x2F;ttymxc0，在 Linux 下，一切皆文件。  </p>
<p>ttymxc0 后面有个“,115200”，这是设置串口的波特率， console&#x3D;ttymxc0,115200 综合起来就是设置 ttymxc0（也就是串口 1）作为 Linux 的终端，并且串口波特率设置为 115200。   </p>
<ul>
<li>（2）root</li>
</ul>
<p>oot 用来设置根文件系统的位置， root&#x3D;&#x2F;dev&#x2F;mmcblk1p2 用于指明根文件系统存放在mmcblk1 设备的分区 2 中。 EMMC 版本的核心板启动 linux 以后会存在&#x2F;dev&#x2F;mmcblk0、&#x2F;dev&#x2F;mmcblk1、 &#x2F;dev&#x2F;mmcblk0p1、 &#x2F;dev&#x2F;mmcblk0p2、 &#x2F;dev&#x2F;mmcblk1p1 和&#x2F;dev&#x2F;mmcblk1p2 这样的文件，其中&#x2F;dev&#x2F;mmcblkx(x&#x3D;0~n)表示 mmc 设备，而&#x2F;dev&#x2F;mmcblkxpy(x&#x3D;0~n,y&#x3D;1~n)表示 mmc 设备x 的分区 y。在 I.MX6U-ALPHA 开发板中&#x2F;dev&#x2F;mmcblk1 表示 EMMC，而&#x2F;dev&#x2F;mmcblk1p2 表示EMMC 的分区 2。</p>
<p>root 后面有“rootwait rw”， rootwait 表示等待 mmc 设备初始化完成以后再挂载，否则的话 mmc 设备还没初始化完成就挂载根文件系统会出错的。 rw 表示根文件系统是可以读写的，不加rw 的话可能无法在根文件系统中进行写操作，只能进行读操作。  </p>
<ul>
<li>（3）rootfstype</li>
</ul>
<p>此选项一般配置 root 一起使用， rootfstype 用于指定根文件系统类型，如果根文件系统为ext 格式的话此选项无所谓。如果根文件系统是 yaffs、 jffs 或 ubifs 的话就需要设置此选项，指定根文件系统的类型。  </p>

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/b353fdae.html">LV05-01-uboot-07-uboot移植</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年09月08日 - 19:23</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/b353fdae.html" title="LV05-01-uboot-07-uboot移植">https://sumumm.github.io/post/b353fdae.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/ALPHA-LV05-uboot%E4%B8%8E%E5%86%85%E6%A0%B8/" rel="tag"><i class="fa fa-tag"></i> (ALPHA)LV05-uboot与内核</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/b7faf544.html" rel="prev" title="LV05-01-uboot-08-uboot图形化配置">
                  <i class="fa fa-angle-left"></i> LV05-01-uboot-08-uboot图形化配置
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/5c91070d.html" rel="next" title="LV05-01-uboot-06-顶层Makefile-02-相关过程分析">
                  LV05-01-uboot-06-顶层Makefile-02-相关过程分析 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
